#! /bin/sh

if [ -f "./env.sh" ]; then  
 source ./env.sh  
fi  

if [ $# -gt 1 ] ; then
 PROJECT_NAME=$2
fi

if [ -z "$PROJECT_NAME" ];then
    echo "PROJECT_NAME not exists and exit"
    exit 1
else  
    echo "PROJECT_NAME=$PROJECT_NAME"  
fi  

#cd ${PROJECT_PATH%/*}
#PROJECT_NAME=${PROJECT_PATH##*/}

COMMAND="java -jar $PROJECT_NAME"
 
start(){
 now=`date "+%Y%m%d%H%M%S"`
 exec $COMMAND  >/dev/null &
}

stop(){
 ps -ef|grep "$COMMAND" |grep -v grep|awk '{print $2}'|while read pid
 do
   kill $pid
 done
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
printf 'Usage: %s {start|stop|restart}\n' "$prog"
exit 1
;;
esac


